﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BullTasDesaDal.Entities;
using BullTasDesaDal.Service;
using System.Text;

namespace WSBulTasDesa.UserControls
{
    public partial class ucDetails : System.Web.UI.UserControl
    {
        private Appraisal appraisal;

        public Appraisal Appraisal
        {
            set
            {
                appraisal = value;
                this.ShowDetails();
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ShowDetails()
        {
            if (appraisal != null)
            {
                this.lblDate.Text = appraisal.DateCreate.ToLongDateString();
                this.lblEstablishmentName.Text = appraisal.EstablishmentName;
                this.lblCatastralNomenclature.Text = appraisal.CatastralNomenclature;
                this.lblOwner.Text = appraisal.Owner;
                this.lblContact.Text = appraisal.Contact;
                this.lblOwnerTel.Text = appraisal.OwnerTel;
                this.lblOwnerMail.Text = appraisal.OwnerMail;
                this.lblHa.Text = appraisal.Ha.ToString();
                this.lblDistanceBA.Text = appraisal.DistanceBA.ToString() + "km";
                StringBuilder revision = new StringBuilder();
                revision.Append( appraisal.RevisionDate.ToShortDateString());
                revision.Append(", ");
                foreach (Revisor revisor in appraisal.Revisors)
                {
                    revision.Append(revisor.Name);
                    revision.Append("/");
                }
                this.lblRevision.Text = revision.ToString();
                this.lblLocation.Text = appraisal.Locality.Name + ", " + appraisal.Locality.Department.Name + ", " + appraisal.Locality.Department.Province.Name;
                this.lblLocationPL.Text = appraisal.LocalityPL.Name + ", " + appraisal.LocalityPL.Department.Name + ", " + appraisal.LocalityPL.Department.Province.Name;
                this.lblLocationPC.Text = appraisal.LocalityPC.Name + ", " + appraisal.LocalityPC.Department.Name + ", " + appraisal.LocalityPC.Department.Province.Name;
                this.grvAnalysis.DataSource = AnalysisService.Get(appraisal.Id);
                this.grvAnalysis.DataBind();
               
            }
        }

        protected void grvAnalysis_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "View")
                Response.Redirect("wfLandAnalysis.aspx?idAnalysis=" + e.CommandArgument.ToString());
        }

       
    }
}